package cn.itcast.daggerdemo;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/8/4.
 */

@Module
@Singleton
public class AppModule {

    private static final String BASE_URL = "http://192.168.209.1:8080/";

    @Provides
    public OkHttpClient provideOkHttpClient() {

           return new OkHttpClient.Builder()
                   .connectTimeout(30 * 1000, TimeUnit.MICROSECONDS)
                   .readTimeout(30 * 1000, TimeUnit.MICROSECONDS)
                   .build();
    }

    @Provides
    public Retrofit prodiveRetrofit(OkHttpClient okHttpClient) {

        return new Retrofit.Builder().baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(okHttpClient)
                .build();
    }

}
